<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>出库单打印</title>
		<script src='${ctxPath}/assets/mui/js/jquery-1.11.3.js'></script>
	</head>
	<style>
		p{
			font-size: 12px;
			margin: 0;
		}
		.button{
			background-color: #A6A6A6; color: black; /* Green */
		    border: none;
		    color: white;
		    padding: 10px 32px;
		    text-align: center;
		    text-decoration: none;
		    display: inline-block;
		    font-size: 14px;
    	}
	</style>
	<body>
		<div style="width: 100%;">
			<button id="button" class="button" onclick="doPrint()">打印</button>
		</div>
		<div id="big" style="width: 100%;">
		</div>
		<script type="text/jscript">
			//通过URL 获取参数
			function GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			};
			var ids = GetQueryString("ids");
			var arrids = [];
			arrids = ids.split(",");
			var now = new Date()
			var year = now.getFullYear()
			var month = now.getMonth()+1
			var day = now.getDate()
			var hour = now.getHours()
			var m = now.getMinutes()
			var s = now.getSeconds()
			var newdate = year+"-"+month+"-"+day+" "+hour+":"+m+":"+s
			function findtou(aa,param){
				return '<div id="-title" style="width: 100%; height: 25px;margin-top: 10px;">'+
					'<p style="float: left; width: 55%;height: 2px;text-align: right;font-size: 18px;font-weight: 600;">'+param.outCustomerName+'出库单</p>'+
					'<p style="float: right; width: 45%;height: 2px;text-align: right;">'+aa+'  打印时间：'+newdate+'</p>'+
				'</div>'+
				'<div id="-title-l" style="width: 100%; height: 20px;">'+
					'<p style="float: left; width: 35%;height: 2px;">收货单位：'+param.getUnit+'</p>'+
					'<p style="float: right;width: 65%; text-align: right;height: 2px;">收货地址：'+param.getLocation+'</p>'+
				'</div>'+
				'<div id="-title-l" style="width: 100%; height: 20px;">'+
					'<p style="float: left; width: 50%;height: 2px;">收货人：'+param.getPeople+'</p>'+
					'<p style="float: right; width: 50%;text-align: right;height: 2px;">收货电话：'+param.getTel+'</p>'+
				'</div>';
			}
			load();
			function load(){
				var big = $("#big");
				//big.append(storageOutmsg);
				for(var i = 0; i <arrids.length; i++){
					$.ajax({
					    url:'${ctxPath}/outOrder/getPrintstorageOut',
					    type:'post',
					    dataType:'json',
					    data:{"id":arrids[i]},
					    success:function(data){
					        if(data!=null){
						 		var storageOuttitle = '<div id="order-title" style="width: 100%;height: 40px;">'+
															'<div id="order-title-1" style="width: 100%;">'+
																'<p style="float: left; width: 28%;">出库单号:'+data.outOrderNumber+'</p>'+
																'<p style="float: left; width: 28%;">客户单号:'+data.customerNumber+'</p>'+
																'<p style="float: left; width: 27%;">货运单号:'+data.transportNumber+'</p>'+
																'<p style="float: left; width: 17%;">制单日期:'+data.setMentiontime+'</p>'+
															'</div>'+	
															'<div id="order-title-2" style="width: 100%;">'+
																'<p style="float: left; width: 30%;">客户采购订单号：'+data.procurementNumber+'</p>'+
																'<p style="float: left; width: 20%;">备货区：'+data.areanumber+'</p>'+
																'<p style="float: left; width: 20%;">车牌号：'+data.privatecarCarnumbers+'</p>'+
																'<p style="float: left; width: 30%;">仓库：'+data.storehouseName+'</p>'+
															'</div>'+
														'</div>';

						 		var storageOutbottom = '<div id="order-title" style="width: 100%;height: 40px;">'+
															'<div id="order-title-1" style="width: 100%;">'+
																'<p style="float: left; width: 25%;">承运人：'+data.driver1+'</p>'+
																'<p style="float: left; width: 25%;">制单人：'+data.createUserName+'</p>'+
																'<p style="float: right; width: 25%;">签收人：</p>'+
																'<p style="float: right; width: 25%;">收货日期：</p>'+
															'</div>'+
															'<div id="order-title-2" style="width: 100%;">'+
																'<p style="float: left; width: 100%;">注：白色为存根联		红色为客户联			黄色财务联</p>'+
															'</div>'+
														'</div>';
								$.ajax({
									url:'${ctxPath}/outOrder/getPrintstorageOutDetailed',
									type:'post',
									dataType:'json',
                					async:false,
									data:{"detailedOutNumber":data.outOrderNumber},
									success:function(data1){
										if(data1.length>0){
											$.each(data1,function(key,value){
												var ncont = 0.0;
												var vcont = 0.0;
												var wcont = 0.0;
												var storageOutdata = '<div id="order-date" style="width: 100%;height: 300px;">'+
																'<table id="order-table" style="width: 100%; font-size: 12px;" border="1px solid" cellpadding="0" cellspacing="0">'+
																	'<thead>'+
																		'<th>物料编号</th>'+
																		'<th>物料描述</th>'+
																		'<th>包装</th>'+
																		'<th>规格</th>'+
																		'<th>数量</th>'+
																		'<th>箱数</th>'+
																		'<th>体积</th>'+
																		'<th>重量</th>'+
																		'<th>批次</th>'+
																		'<th>实收数</th>'+
																		'<th>备注</th>'+
																	'</thead>'+
																	'<tbody>';
												$.each(value.list,function(key1,value1){
													ncont += value1.detailedNumber*1;
													vcont += value1.detailedOutVolume*1;
													wcont += value1.detailedOutWeight*1;
													storageOutdata += '<tr>'+
																			'<td>'+value1.detailedGoodscode+'</td>'+
																			'<td>'+value1.detailedGoodsname+'，'+value1.goodsNo+'</td>'+
																			'<td>'+value1.detailedPacking+'</td>'+
																			'<td>'+value1.goodsSpecs+'</td>'+
																			'<td>'+value1.detailedNumber+'</td>';
																			if(value1.xianggui != null && value1.xianggui != ''){
																				var xiang = parseInt(value1.detailedNumber/value1.xianggui)
																				var he = value1.detailedNumber-parseInt(value1.detailedNumber/value1.xianggui)*value1.xianggui
																				storageOutdata += '<td>'+xiang+'箱'+he+'盒</td>';
																			} else {
																				storageOutdata += '<td></td>';
																			}
																			storageOutdata += 
																			'<td>'+value1.detailedOutVolume+'</td>'+
																			'<td>'+value1.detailedOutWeight+'</td>'+
																			'<td>'+value1.detailedBatchnumber+'</td>'+
																			'<td></td>'+
																			'<td></td>'+
																		'</tr>';
												});
												storageOutdata += '<tr>'+
																		'<td></td>'+
																		'<td>小计：</td>'+
																		'<td></td>'+
																		'<td></td>'+
																		'<td>'+Math.round(ncont * 100) / 100+'</td>'+
																		'<td></td>'+
																		'<td>'+Math.round(vcont * 100) / 100+'</td>'+
																		'<td>'+Math.round(wcont * 100) / 100+'</td>'+
																		'<td></td>'+
																		'<td></td>'+
																		'<td></td>'+
																	'</tr>';
												storageOutdata += '<tr>'+
																		'<td></td>'+
																		'<td>合计：</td>'+
																		'<td></td>'+
																		'<td></td>'+
																		'<td>'+data.detailedNumber+'</td>'+
																		'<td></td>'+
																		'<td>'+data.detailedOutVolume+'</td>'+
																		'<td>'+data.detailedOutWeight+'</td>'+
																		'<td></td>'+
																		'<td></td>'+
																		'<td></td>'+
																	'</tr>';
												storageOutdata += '</tbody>'+
															'</table>'+
														'</div>';
												var tou = findtou('第'+(key+1)+'页  '+'共'+data1.length+'页',data)
												big.append(tou+storageOuttitle+storageOutdata+storageOutbottom);
											});
										}else{
								 			alert("未查询到出库单明细!");
										}
									},
									error:function(data){
										alert("查询出库单明细异常!");
									}
								});
					 		}else{
					 			alert("未查询到出库单!");
					 		}
					    },
					    error: function(data){
							alert("查询出库单异常!");
					    }
					});
				}
			};
			//打印
			function doPrint() {
		        bdhtml = window.document.body.innerHTML;
		        phtnl = window.document.getElementById("big").innerHTML;
		        window.document.body.innerHTML = phtnl; //把需要打印的指定内容赋给big
		        window.print(); //调用浏览器的打印功能打印指定区域
		        window.document.body.innerHTML=bdhtml; // 最后还原页面
		    };
		    //打印的回调
		    var beforePrint = function() {
		        //打印前调用
		    };
		    var afterPrint = function() {
		        //打印后调用
            	var Indexs = parent.layer.getFrameIndex(window.name);
                parent.layer.close(Indexs);
		    };
		    if (window.matchMedia) {
		        var mediaQueryList = window.matchMedia('print');
		        mediaQueryList.addListener(function(mql) {
		            if (mql.matches) {
		                beforePrint();
		            } else {
		                afterPrint();
		            }
		        });
		    }
		</script>
	</body>
</html>